<?php


namespace app\index\controller;


use app\common\controller\UserController;
use app\common\helper\util\Crypt;

class UserCenter extends UserController
{
    /**
     * 获取自己
     */
    function user(){
        self::$user->password = '';
        $this->result_success(self::$user);
    }

    /**
     * 编辑资料
     */
    function update_user(){
        $param = input();
        if(isset($param["passsword"]) && !empty($param["passsword"])){
            self::$user->password = Crypt::pwd($param["passsword"]);
        }
        if(isset($param["avatar"]) && !empty($param["avatar"])){
            self::$user->avatar = $param["avatar"];
        }
        self::$user->save();
        $this->result_success();
    }

    /**
     * 获取钱
     */
    function money(){
        $user = $this->getUser();
        $data = $user->getMoney();
        $this->result_success($data);
    }

    /**
     * 获取消息
     */
    function msg(){
        $user = $this->getUser();
        $data = $user->getMsg();
        $this->result_success($data);
    }

    /**
     * 获取支付
     */
    function payment(){
        $user = $this->getUser();
        $data = $user->getPayment();
        $this->result_success($data);
    }

    /**
     * 获取雇主
     */
    function employ(){
        $user = $this->getUser();
        $data = $user->getEmploy();
        $this->result_success($data);
    }

    /**
     * 更新雇主
     */
    function update_employ(){
        $param = input();
        $user = $this->getUser();
        $data = $user->getEmploy();
        $data->save($param);
        $this->result_success($data);
    }

    /**
     * 获取服务商
     */
    function server(){
        $user = $this->getUser();
        $data = $user->getServer();
        $this->result_success($data);
    }

    /**
     * 更新服务商
     */
    function update_server(){
        $param = input();
        $user = $this->getUser();
        $data = $user->getServer();
        $data->save($param);
        $this->result_success($data);
    }

    /**
     * 全部个人信息
     */
    function detail(){
        $user = $this->getUser();
        $data = $user->getDetail();
        $this->result_success($data);
    }

    /**
     * 更新个人信息
     */
    function update_detail(){
        $key = input("key");
        $value = input("value");
        $user = $this->getUser();
        $data = $user->setDetail($key,$value);
        $this->result_success($data);
    }

}